var express = require('express');
var router = express.Router();
var fs = require('fs');


function onRequest(req,res){
    console.log('request');
    
    var tmp_path = String(req.files.userfile.path);
    var target_path = './img/'+req.files.userfile.name;
    console.log(req.files);
    fs.rename(tmp_path,target_path,function(err){
        if(err){
            throw err;
        }
        
    })
    console.log(
        tmp_path+'</br>'+
        target_path
    );
    res.writeHead(200,{'Access-Control-Allow-Origin':'*','Content-Language':'en,zh','Content-Type': 'application/json; charset=utf-8'});

    res.end('OK'+tmp_path+' tar:'+target_path);
}


router.post('/',onRequest);
module.exports = router;